package com.open.capacity.exam.controller;

import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.exam.service.PaperService;
import com.open.capacity.exam.vo.PaperVo;
import com.open.capacity.exam.vo.QuestionsVo;
import com.open.capacity.exam.vo.PaperConditionParam;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "考卷管理")
@RequestMapping("examPaper")
public class PaperController {
    @Autowired
    private PaperService paperService;

    /**
     * 生成考卷
     * @param examPaper
     * @return
     */
    @PostMapping("/addPaper")
    public Result addPaper(@RequestBody PaperVo examPaper){
        return paperService.addPaper(examPaper);
    }

    /**
     * 根据选择的考题类型和数量添加到试卷
     * @param param
     * @return
     */
    @PostMapping("/addPaperQue")
    public Result addPaperQue(@RequestBody List<PaperConditionParam> param){
        return paperService.addPaperQue(param);
    }

    /**
     * 模糊查询
     * @param param
     * @return
     */
    @GetMapping("/findPaper")
    public PageResult<PaperVo> findPaper(@RequestParam Map<String,Object> param){
        return paperService.findPaper(param);
    }

    /**
     * 根据考卷id查询考题信息
     * @param expaid
     * @return
     */
    @GetMapping("/findPaperQue")
    public PageResult<QuestionsVo> findPaperQuestions(Integer expaid){
        return  paperService.findPaperQuestions(expaid);
    }

    /**
     * 删除试卷，同时删除对应的考题、用户关系表
     * @param expaid
     * @return
     */
    @PostMapping("/removePaper/{expaid}")
    public Result removePaper(@PathVariable Integer expaid){
        return paperService.removePaper(expaid);
    }


}
